package com.markerhub.controller;

import com.markerhub.common.lang.Result;
import com.markerhub.common.vo.ClassVO;
import com.markerhub.common.vo.ClassmateVO;
import com.markerhub.entity.User;
import com.markerhub.service.StudentClassService;
import com.markerhub.shiro.AccountProfile;  // 确保导入正确的 AccountProfile
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentClassController {

    @Autowired
    private StudentClassService studentClassService;

    @GetMapping("/my-classes")
    public Result getMyClasses() {
        Subject subject = SecurityUtils.getSubject();
        AccountProfile accountProfile = (AccountProfile) subject.getPrincipal();
        Long studentId = accountProfile.getId();
        List<ClassVO> classes = studentClassService.getStudentClasses(studentId);
        return Result.succ(classes);
    }

    @GetMapping("/class-details/{classId}")
    public Result getClassDetails(@PathVariable Integer classId) {
        Subject subject = SecurityUtils.getSubject();
        AccountProfile accountProfile = (AccountProfile) subject.getPrincipal();
        Long studentId = accountProfile.getId();

        List<ClassmateVO> classmates = studentClassService.getClassmates(classId, studentId);
        return Result.succ(classmates);
    }
}